﻿using System;
using System.Collections.Generic;

using HelfenHelfen.DataAccess.Factories;
using HelfenHelfen.DataAccess.Interfaces;
using HelfenHelfen.Logic.Interfaces;
using LE = HelfenHelfen.DataAccess.Entities;
using HelfenHelfen.Logic.Entities;
// using HelfenHelfen.Logic.Utility;

namespace HelfenHelfen.Logic {
   public class DemandLogic : IDemandLogic {

      public void Insert(LE.Demand newDemand) {
         throw new NotImplementedException();
      }

      public void Update(LE.Demand updateDemand) {
         throw new NotImplementedException();
      }

      public void Delete(Guid demandId) {
         throw new NotImplementedException();
      }

      public DemandDetailView GetDetailView(Guid demandId){
         var obj = new DemandDetailView();
         obj.Demand = Get(demandId);

         var da = DataAccessFactory.CreateImageDataAccess();
         obj.Image = da.GetByDemand(obj.Demand.DemandGUID);

         var da2 = DataAccessFactory.CreateDemandDetailDataAccess();
         obj.DemandDetail = da2.GetAllByDemand(obj.Demand.DemandGUID);

         var da3 = DataAccessFactory.CreateOrganisationDataAccess();
         obj.Organisation = da3.Get(obj.Demand.OrganisationGUID);

         var da4 = DataAccessFactory.CreateUserDetailDataAccess();
         obj.UserDetail = da4.Get(obj.Demand.ContactPersonUserDetailGUID);

         return obj;
      }

      public LE.Demand Get(Guid demandId) {
         var da = DataAccessFactory.CreateDemandDataAccess();
         LE.Demand demand = da.Get(demandId);

//         var daImage = DataAccessFactory.CreateImageDataAccess();
//         Image image = daImage.GetByDemand(demand.DemandGUID);

         return demand;

//       return LE.DemandExtView.ToDemandExtView(demand, image);
      }

/*
      virtual public IList<DemandExtView> GetAll() {
         var newList = new List<DemandExtView>();

         // Do some validation, ... here
         var da = DataAccessFactory.CreateDemandDataAccess();
         IList<HelfenHelfen.DataAccess.Entities.Demand> oldList = da.GetAll(9999);

         var daImage = DataAccessFactory.CreateImageDataAccess();

         foreach (HelfenHelfen.DataAccess.Entities.Demand demand in oldList) {
            Image image = daImage.GetByDemand(demand.DemandGUID);
            newList.Add( DemandExtView.ToDemandExtView(demand, image));
         }

         return newList;
      }
*/

      public IList<LE.Demand> GetAll() {
         // Do some validation, ... here
         var da = DataAccessFactory.CreateDemandDataAccess();
         return da.GetAll(9999, string.Empty, Guid.Empty, null);
      }

      public IList<LE.Demand> GetAllHighlights(){
         // Do some validation, ... here
         var da = DataAccessFactory.CreateDemandDataAccess();
         return da.GetAll(2, string.Empty, Guid.Empty, null);
      }


      public IList<LE.Demand> GetAll(string city, Guid category, DateTime? date){
         // Do some validation, ... here
         var da = DataAccessFactory.CreateDemandDataAccess();
         return da.GetAll(9999, city, category, date);
      }



      public IList<string> GetAllCities() {
         var da = DataAccessFactory.CreateDemandDataAccess();
         var obj = da.GetAllCities();
         obj.Insert(0, "(Alle Städte)");
         return obj;
      }

/*
      public IList<LE.Demand> GetAllFilter(string city, Guid category){
         var newList = new List<LE.Demand>();

         // Do some validation, ... here
         var da = DataAccessFactory.CreateDemandDataAccess();
*//*         IList<Demand> oldList = da.GetAllFilter(city, category);

         var daImage = DataAccessFactory.CreateImageDataAccess();

         foreach (Demand demand in oldList) {
            Image image = daImage.GetByDemand(demand.DemandGUID);
            newList.Add(DemandExtView.ToDemandExtView(demand, image));
         }
*/

/*
         var daImage = DataAccessFactory.CreateImageDataAccess();

         da.GetAllFilter(city, category).ForEach(demand => {
            Image image = daImage.GetByDemand(demand.DemandGUID);
            newList.Add(LE.Demand.ToDemandExtView(demand, image));
         });






         return newList;



      }
*/
   //<ppt id=4 />
   }
}
